package main

import "fmt"
import "os"

func generateFibonacci() [50]int {
	var arr [50]int
	arr[0] = 1
	arr[1] = 1
	for i := 2; i < 50; i++ {
		arr[i] = arr[i-2] + arr[i-1]
	}
	for i := 0; i < 50; i++ {
		fmt.Printf("arr[%d]=%d\n", i, arr[i])
	}
	return arr
}
func isFibonacci(n int) bool {
	var arr [50]int = generateFibonacci()
	for i := 0; i < 50; i++ {
		if n == arr[i] {
			//fmt.Printf("n==arr[%d]=%v\n", i, n == arr[i])
			return true
		}
	}
	return false

}
func WriteFile(path string) {
	f, err := os.Create(path)
	if err != nil {
		fmt.Println("打开文件异常")
		return
	}
	fmt.Println("输出判断到fibonacci.txt....")
	for i := 2; i <= 30000; i++ {
		if isFibonacci(i) == true {
			fmt.Println("i=", i)
			buf := fmt.Sprintf("i=%d\n", i)
			f.WriteString(buf)
		} else {
			continue
		}
	}
	fmt.Println("输出完毕")
	defer f.Close()
}
func main() {
	path := "../target/fibonacci.txt"
	WriteFile(path)
}
